<?php

namespace Common\Model;

use Think\Model;

class CommentModel extends Model {

    /**
     *  添加
     *  @param $where
     */
    public function addComment($data) {
        $result = $this->data($data)->add();

        return $result;
    }

    /**
     *  获取列表
     *  @param $where
     */
    public function getCommentList($page = 1, $pageSize = 15, $where = array(), $order = "") {
        $pre = C("DB_PREFIX");
        $result = M("Comment cm")
                ->field("cm.commentID commentID,cm.masterID masterID,cm.userID userID,cm.content content,"
                        . "cm.serviceGrade serviceGrade,cm.skillGrade skillGrade,cm.timeGrade timeGrade,"
                        . "cm.addTime addTime,cm.isHide isHide,cm.isKind isKind,cm.isExtra isExtra,cm.isWechat isWechat,cm.isOnTime isOnTime,cm.isPersonal isPersonal,"
                        . "ur.nickName nickName,ur.phone phone,mt.name masterName,mt.phone masterPhone")
                ->join("LEFT JOIN $pre"."user ur on cm.userID = ur.userID LEFT JOIN $pre"."master mt on cm.masterID = mt.masterID")
                ->where($where)->page($page, $pageSize)->order($order)->select();
        return $result;
    }

    /**
     *  获取总数
     *  @param $where
     */
    public function getCommentListLength($where = array()) {
        $result = M("Comment cm")->where($where)->count();
        return $result;
    }

}

?>